package com.zjzywl.smoke.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.zjzywl.smoke.entity.Organization;

@Repository
public interface OrganizationRepository extends JpaRepository<Organization, Integer> {

	@Query("select u from Organization u where orgid =:orgid")
	Organization findByOrgid(@Param("orgid") String orgid);

	@Query("select u from Organization u where id =:id")
	Organization findById(@Param("id") Integer id);

	@Query("select u from Organization u order by level")
	List<Organization> findOrderLevel();

	@Query("select u from Organization u where parent.id =:parentId")
	List<Organization> findByParentOrg(@Param("parentId") Integer parentId);

	@Query("select u from Organization u where path like :path and u.Remove=null and u.type=:type order by level")
	List<Organization> findByPath(@Param("path") String path, @Param("type") String type);

	@Query("select u from Organization u where path like :path and u.Remove=null  order by level")
	List<Organization> findByPathAll(@Param("path") String path);

	Organization findOne(Integer id);

	@Query("select u from Organization u where path like :path and u.Remove=null order by level")
	List<Organization> findAllByPath(@Param("path") String path);
}
